package com.huixh.train.business.controller.web;

import com.huixh.train.business.req.ConfirmOrderQueryReq;
import com.huixh.train.business.req.ConfirmOrderDoReq;
import com.huixh.train.business.resp.ConfirmOrderQueryResp;
import com.huixh.train.business.service.ConfirmOrderService;
import com.huixh.train.business.service.impl.BeforeConfirmOrderServiceImpl;
import com.huixh.train.common.resp.PageResult;
import com.huixh.train.common.resp.Result;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author huixh
*/
@Validated
@RestController
@RequestMapping("/confirm-order")
public class ConfirmOrderController {
    @Resource
    private ConfirmOrderService confirmOrderService;
    @Resource
    private BeforeConfirmOrderServiceImpl beforeConfirmOrderServiceImpl;

    @PostMapping("/save")
    public Result<?> save(@RequestBody @Valid ConfirmOrderDoReq confirmOrderDoReq) {
    confirmOrderService.save(confirmOrderDoReq);
        return Result.success();
    }

    @PostMapping("/quest-list")
    public PageResult<List<ConfirmOrderQueryResp>> query(@RequestBody @Valid ConfirmOrderQueryReq confirmOrderQueryReq) {
        return confirmOrderService.queryList(confirmOrderQueryReq);
    }

    @DeleteMapping("/delete/{id}")
    public Result<?> deleteById(@NotNull @PathVariable(name = "id") Long id) {
        confirmOrderService.delete(id);
        return Result.success("删除成功");
    }
    @PostMapping("/do")
    public Result<String> doConfirmOrder(@Valid @RequestBody ConfirmOrderDoReq confirmOrderDoReq) {
        Long aLong = beforeConfirmOrderServiceImpl.beforeConfirmOrder(confirmOrderDoReq);
        Result<String> result = Result.success("下单成功！");
        result.setData(String.valueOf(aLong));
        return result;
    }

    @GetMapping("/query-line-count/{id}")
    public Result<Integer> queryLineCount(@PathVariable(name = "id")Long id){
        Integer count = confirmOrderService.queryLineCount(id);
        return Result.success(count);
    }
}